import matplotlib.pyplot as plt
import numpy as np

# 计算正弦图上的x 和 y
x = np.arange(0, 3*np.pi, 0.1)
y = np.sin(x)

# 绘制散点图
plt.scatter(x, y,
            s=5,
            c=y,
            marker="s",
            cmap="gray"
            )

plt.show()

import matplotlib.pyplot as plt
import numpy as np

# 定义随机数组
x = np.random.rand(50)
y = np.random.rand(50)
sizes = 100 * np.random.rand(50)
colors = np.random.rand(50)

# 绘制散点图
plt.scatter(x, y, s=sizes, c=colors)

plt.show()

import matplotlib.pyplot as plt
import numpy as np

# 准备数据
x = ["A", "B", "C", "D", "E"]
values = [20, 35, 30, 25, 10]

# 绘制条形图
plt.bar(x, height=values, color="skyblue")

plt.show()

import matplotlib.pyplot as plt
import numpy as np

# 准备数据
x = [1, 2, 5, 4]
labels = ['A', 'B', 'C', 'D']
explode = [0, 0, 0.05, 0]   # 0.05表示相对于半径的百分比

# 绘制饼图
plt.pie(x,
        explode=explode,            # 扇形是否突出显示
        labels=labels,              # 添加标签
        autopct="%1.1f%%",          # 显示扇形百分比的字符串格式
        startangle=45,              # 开始角度
        textprops={"color":"skyblue", "size":12}    # 设置标签的文本样式
        )

plt.show()

import matplotlib.pyplot as plt
import numpy as np

# 准备数据
x = np.random.randn(1000)       # 符合标准正态分布的数据

x[10] = 10

# 绘制直方图
plt.hist(x, bins=10, density=True)  # 归一化的概念先有个印象，后面继续讲

plt.show()

import matplotlib.pyplot as plt
import numpy as np

# 准备数据
x = [np.random.normal(0, std, 100)
     for std in range(1, 4)]

# 绘制箱线图
plt.boxplot(x)

plt.show()